package cn.itsource.pet.controller;

import cn.itsource.basic.util.AjaxResult;
import cn.itsource.pet.domain.SearchMasterMsg;
import cn.itsource.pet.query.SearchMasterMsgQuery;
import cn.itsource.pet.service.ISearchMasterMsgService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 宠物接单类
 */
@RestController
@Api(tags = "宠物接单类", description = "宠物接单类")
@RequestMapping("/searchMasterMsg")
public class SearchMasterMsgController {

    @Autowired
    private ISearchMasterMsgService searchMasterMsgService;


    /**
     * 分页查询
     * @return
     */
    @PostMapping("/findPage")
    @ApiOperation(value = "分页查询",notes = "可以分页查询所有的接单")
    public AjaxResult findPage(@RequestBody SearchMasterMsgQuery query){
        return AjaxResult.createSuccess(searchMasterMsgService.findPage(query));
    }

    /**
     * 新增或者修改,根据id区分
     * @return
     */
    @PostMapping
    @ApiOperation(value = "新增修改",notes = "可以根据id区分操作")
    public AjaxResult saveOrUpdate(@RequestBody SearchMasterMsg searchMasterMsg){

        //根据id区分,没有id就是新增
        try {
            searchMasterMsgService.saveOrUpdate(searchMasterMsg);

            return AjaxResult.createSuccess();
        } catch (Exception e) {

            e.printStackTrace();
            return AjaxResult.createError("操作异常,联系管理员李裕");
        }
    }

    /**
     * 删除接单根据id
     * @return
     * 接受请求： /emp/12
     */
    @DeleteMapping("/{id}")
    @ApiOperation(value = "删除操作",notes = "根据id删除接单")
    public AjaxResult delete(@PathVariable("id") Long id){

        //根据id区分,没有id就是新增
        try {
            //调用删除
            searchMasterMsgService.delete(id);

            return AjaxResult.createSuccess();
        } catch (Exception e) {

            e.printStackTrace();
            return AjaxResult.createError("操作异常,联系管理员李裕");
        }
    }

}
